Proper connect_port
[juce-lv2.git] / juce / source / extras / the jucer / src / properties / jucer_ComponentColourProperty.h
blob678adbed421c7819b8715bddcec61adca24dd1c3
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_COMPONENTCOLOURPROPERTY_JUCEHEADER__
27 #define __JUCER_COMPONENTCOLOURPROPERTY_JUCEHEADER__
29 #include "jucer_ColourPropertyComponent.h"
32 //==============================================================================
33 /**
35 template <class ComponentType>
36 class ComponentColourProperty : public ColourPropertyComponent,
37 private ChangeListener
39 public:
40 ComponentColourProperty (const String& name,
41 ComponentType* component_,
42 JucerDocument& document_,
43 const bool canResetToDefault)
44 : ColourPropertyComponent (name, canResetToDefault),
45 component (component_),
46 document (document_)
48 document.addChangeListener (this);
51 ~ComponentColourProperty()
53 document.removeChangeListener (this);
56 void changeListenerCallback (ChangeBroadcaster*)
58 refresh();
61 protected:
62 ComponentType* component;
63 JucerDocument& document;
67 //==============================================================================
68 /**
70 class ComponentColourIdProperty : public ComponentColourProperty <Component>
72 public:
73 //==============================================================================
74 ComponentColourIdProperty (Component* const component_,
75 JucerDocument& document_,
76 const int colourId_,
77 const String& name,
78 const bool canResetToDefault)
79 : ComponentColourProperty <Component> (name, component_, document_, canResetToDefault),
80 colourId (colourId_)
84 ~ComponentColourIdProperty()
88 //==============================================================================
89 const Colour getColour() const
91 return component->findColour (colourId);
94 void setColour (const Colour& newColour)
96 if (component->findColour (colourId) != newColour)
98 document.getUndoManager().undoCurrentTransactionOnly();
100 document.perform (new ColourChangeAction (component,
101 *document.getComponentLayout(),
102 colourId,
103 newColour,
104 false),
105 "Change colour");
109 void resetToDefault()
111 document.getUndoManager().undoCurrentTransactionOnly();
113 document.perform (new ColourChangeAction (component,
114 *document.getComponentLayout(),
115 colourId,
116 Colours::black,
117 true),
118 "Reset colour");
121 private:
122 const int colourId;
124 class ColourChangeAction : public ComponentUndoableAction <Component>
126 public:
127 ColourChangeAction (Component* const comp,
128 ComponentLayout& layout,
129 const int colourId_,
130 const Colour& newColour_,
131 const bool newColourIsDefault)
132 : ComponentUndoableAction <Component> (comp, layout),
133 colourId (colourId_),
134 newColour (newColour_),
135 isDefault (newColourIsDefault)
139 bool perform()
141 showCorrectTab();
143 wasSpecified = getComponent()->isColourSpecified (colourId);
144 oldColour = getComponent()->findColour (colourId);
146 if (isDefault)
147 getComponent()->removeColour (colourId);
148 else
149 getComponent()->setColour (colourId, newColour);
151 changed();
152 return true;
155 bool undo()
157 showCorrectTab();
159 if (wasSpecified)
160 getComponent()->setColour (colourId, oldColour);
161 else
162 getComponent()->removeColour (colourId);
164 TextEditor* const te = dynamic_cast <TextEditor*> (getComponent());
165 if (te != 0)
166 te->applyFontToAllText (te->getFont());
168 changed();
169 return true;
172 int colourId;
173 Colour newColour, oldColour;
174 bool isDefault, wasSpecified;
179 #endif // __JUCER_COMPONENTCOLOURPROPERTY_JUCEHEADER__